<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图书管理</title>
	<jsp:include page="/pages/common/head.jsp"></jsp:include>

	<script>
		//给删除的a标签绑定单机事件，用于删除的确认提示操作
		$(function (){
			$("a.deleteClass").click(function (){
				const book_name = $(this).parent().siblings("td").eq(0).text();
				return confirm("你确定要删除【" + book_name + "】?");
			});

			//跳到指定的页码
			$("#searchPageBtn").click(function (){
				let pageNo = $("#pn_input").val();

				//location地址栏对象
				//有一个属性叫href,它可以获取浏览器地址栏中的地址
				//href属性可读，可写
				location.href = "${pageScope.basePath}${requestScope.page.url}&pageNo=" + pageNo;
			});
		});
	</script>

	<style>
		#main .modifyBtn{
			display: inline-block;
			padding: 0 5px;
			background-color: #e6a23c;
			transition: 0.1s;
			font-size: 17px;
			color: #fff;
			text-decoration: none;
			border-radius: 3px;
		}

		#main .modifyBtn:hover{
			background-color: #e0b471;
		}

		#main .deleteClass{
			display: inline-block;
			padding: 0 5px;
			background-color: #f56c6c;
			transition: 0.1s;
			font-size: 17px;
			color: #fff;
			text-decoration: none;
			border-radius: 3px;
		}
		#main .deleteClass:hover{
			background-color: #f78989;
		}
	</style>

</head>
<body>
	
	<div id="header">

			<span class="wel_word">图书管理</span>
			<%@include file="/pages/common/manager_menu.jsp"%>

	</div>
	
	<div id="main">
		<table>
			<tr>
				<td>名称</td>
				<td>价格</td>
				<td>作者</td>
				<td>销量</td>
				<td>库存</td>
				<td colspan="2">操作</td>
			</tr>		


			<c:forEach items="${requestScope.page.items}" var="book">
				<tr>
					<td>${book.name}</td>
					<td>${book.price}</td>
					<td>${book.author}</td>
					<td>${book.sales}</td>
					<td>${book.stock}</td>
					<td><a class="modifyBtn" href="manager/bookServlet?action=getBook&id=${book.id}&pageNo=${requestScope.page.pageNo}">修改</a></td>
					<td><a class="deleteClass" href="manager/bookServlet?action=delete&id=${book.id}&pageNo=${requestScope.page.pageNo}">删除</a></td>
				</tr>
			</c:forEach>

			
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td><a href="./pages/manager/book_edit.jsp?pageNo=${requestScope.page.pageTotal}">添加图书</a></td>
			</tr>	
		</table>

		<%--静态包含分页条--%>
		<%@include file="/pages/common/page_nav.jsp"%>
	</div>

	<%--静态包含页脚内容--%>
	<%@include file="/pages/common/foot.jsp"%>
</body>
</html>